package engine;

import java.text.DecimalFormat;
import java.util.ArrayList;
import utilities.MatLabCOM;

public class Candidate {

    private ArrayList<Double> values;
    private double fitnessValue;
    boolean matchConstraint;

    public ArrayList<Double> getValues() {
        return values;
    }

    public Candidate(ArrayList<Double> _vector) {
        this.values = _vector;
    }

    @Override
    public String toString() {
        
        String toPrint = "";

        toPrint += "{";
        for (Double d : values) {
            toPrint += new DecimalFormat("#.##").format(d) + ", ";
        }
        toPrint = toPrint.substring(0, toPrint.length() - 2);//suppression du dernier ", "

        toPrint += "}";

        return toPrint;
    }

    /*
     * Retourne vrai si le candidat match les équations <= 0
     * 
     */
    public Boolean matchEquations(ArrayList<Equation> equations, MatLabCOM matlab) {
        Boolean match = true;

        for (Equation eq : equations) {
            if (matlab.evaluate(eq, this) > 0) {
                match = false;
            }
        }

        return match;
    }

    public double getFitnessValue() {
        return fitnessValue;
    }

    public void setFitnessValue(double _fitnessValue) {
        this.fitnessValue = _fitnessValue;
    }
}
